using System;
using System.Collections.Generic;
using System.Text;

namespace Devsoft.Utilities
{
    public class RandomHelper
    {
        protected static String BASE_64_CHARACTER = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        public static String GenerateRandomString(int nLength)
        {
            StringBuilder sb = new StringBuilder();
            System.Random autoRand = _Random;
            int n = BASE_64_CHARACTER.Length;
            for (int i = 0; i < nLength ; i++)
            {
                sb.Append(BASE_64_CHARACTER[autoRand.Next(n)]);                                
            }
            return sb.ToString();

        }

        public static String GenerateUniqueString()
        {
            return Cipher.MD5(GenerateRandomString(32) + RandomNumber().ToString() + DateTime.Now.ToFileTimeUtc());
        }

        public static int RandomNumber()
        {
            return _Random.Next();
        }
        public static int RandomNumber(int max)
        {
            return _Random.Next(max);
        }

        protected static Random _Random = new System.Random((int)DateTime.Now.ToFileTimeUtc()+System.Environment.TickCount);
    }
}
